package com.ruoyi.common.distributeLock.service;

import com.ruoyi.common.distributeLock.configure.CuratorClient;
import org.apache.curator.framework.recipes.locks.InterProcessMutex;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author gim 2023/4/18 15:46
 */
@Component
public class ZkService {
    @Autowired
    private CuratorClient curatorClient;

    public void testLock(){
        String threadName=Thread.currentThread().getName();

        InterProcessMutex mutex=new InterProcessMutex(curatorClient.getClient(),"/lock");

        try{
            boolean lockFlag=mutex.acquire(3000, TimeUnit.SECONDS);
        }catch (Exception e){

        }finally {

        }
    }
}
